<template>
  <div>
    <span v-if="error" style="background: red; color: white"
      >发生了错误，显示在这里</span
    >
    <slot v-else></slot>
  </div>
</template>

<script>
export default {
  name: "ErrorBoundary",
  data() {
    return {
      error: null,
    };
  },
  errorCaptured(err, vm, info) {
    console.error("this.error", err, vm, info);
    this.error = `${err.stack}\n\nfound in ${info} of component`;
    return false;
  },
};
</script>

<style></style>
